#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <stdbool.h>
    int fun(int n)
    {
        int k = 0, sum = 0;
        while (n != 0)
        {
            k = n % 10;
            sum += k * k;
            n /= 10;
        }
        return sum;
    }
bool isHappy(int n) {

    int cur = n;
    int dest = fun(n);
    while (cur!= dest)
    {
        cur = fun(cur);
        dest = fun(fun(dest));
    }
    if (cur == 1)
        return true;
    else
        return false;

}

int main()
{
    int n;
    scanf("%d", &n);
    printf("%d",isHappy(n));
    return 0;
}